<template>
  <el-container class="manager-container">
    <el-aside width="200px">
      <div class="sidebar-header">管理端</div>
      <el-menu
        :default-active="activeMenu"
        class="el-menu-vertical"
        @select="handleSelect"
        background-color="#304156"
        text-color="#fff"
        active-text-color="#409EFF"
      >
        <el-menu-item index="/manager/employees">
          <el-icon><User /></el-icon>
          <span>员工管理</span>
        </el-menu-item>
        <el-menu-item index="/manager/customers">
          <el-icon><Avatar /></el-icon> 
          <span>客户管理</span>
        </el-menu-item>
        <el-menu-item index="/manager/rooms">
          <el-icon><OfficeBuilding /></el-icon>
          <span>会议室管理</span>
        </el-menu-item>
        <el-menu-item index="/manager/devices">
          <el-icon><Monitor /></el-icon>
          <span>媒体设备管理</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    
    <el-container>
      <el-header>
        <div class="header-left">
          <h2 style="margin: 0; font-size: 18px;">会议室管理系统</h2>
        </div>
        <div class="header-right">
          <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link">
              管理员
              <el-icon><ArrowDown /></el-icon>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item command="logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </el-header>
      
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { User, OfficeBuilding, ArrowDown, Avatar, Monitor } from '@element-plus/icons-vue' 
import { ElMessage, ElMessageBox } from 'element-plus'

const router = useRouter()
const activeMenu = ref(router.currentRoute.value.path)

const handleSelect = (index) => {
  router.push(index)
}

const handleCommand = (command) => {
  if (command === 'logout') {
    logout()
  }
}
const logout = () => {
  ElMessageBox.confirm('确定要退出登录吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    localStorage.removeItem('token')
    localStorage.removeItem('user')
    router.replace({ path: '/manager/login' })
    ElMessage.success('已退出管理员端登录')
  }).catch(() => {
    return
  })
}
</script>

<style scoped>
.manager-container {
  height: 100vh;
}

.el-menu-vertical {
  height: 100%;
  border-right: none;
}

.el-header {
  background-color: #fff;
  border-bottom: 1px solid #e6e6e6;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  height: 50px !important;
}

.header-right .el-dropdown-link {
  cursor: pointer;
  display: flex;
  align-items: center;
  color: #409EFF;
}

.header-right .el-dropdown-link .el-icon {
  margin-left: 8px;
}

.sidebar-header {
  height: 50px;
  line-height: 50px;
  text-align: center;
  color: #fff;
  font-size: 20px;
  font-weight: bold;
  letter-spacing: 2px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  background-color: #263445;
  border-bottom: 2px solid #1f2d3d;
  padding: 0 10px;
}
</style>